package com.example.template.service;

import com.example.template.service.comand.AddStudentCommand;
import com.example.template.service.comand.AddStudentCommandReceiver;
import com.example.template.service.comand.AddStudentCompletedEvent;
import com.example.template.service.comand.DeleteStudentCommand;
import com.google.common.eventbus.EventBus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class StudentService implements
        AddStudentCommandReceiver,
        DeleteStudentCommand.Receiver {

    @Autowired
    private EventBus bus;

    @Override
    public void action(AddStudentCommand command) {
        System.out.println("【添加学生】具体的业务逻辑代码");

        // 发出【通知】：【添加学生】已经干完了！
        System.out.println("发出通知");
        bus.post(new AddStudentCompletedEvent(9527));
    }

    @Override
    public void action(DeleteStudentCommand command) {
        System.out.println("执行删除学生的代码逻辑");
    }

}
